package com.webserver.core;

import com.sun.javafx.binding.StringFormatter;
import com.webserver.controller.UserController;
import com.webserver.http.HttpContext;
import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class DispatcherServlet {
    public void service(HttpServletRequest request, HttpServletResponse response){
        //2.处理请求
       // String path=request.getUri();
        String path=request.getRequestURI();
        System.out.println("请求抽象路径:"+path);
        //首先判断是否为请求一个业务处理
        if ("/myweb/reg".equals(path)){
            UserController controller=new UserController();
            controller.reg(request,response);
        }else if ("./myweb/login".equals(path)){
            UserController controller=new UserController();
            controller.reg(request,response);
        }else {
            File file = new File("./webapps" + path);
            //状态相关信息

            if (file.isFile()) {
                response.setContentFile(file);
            } else {
                response.setStausCode(404);
                response.setStausReason("Not Found");
                file = new File("./webapps/root/404.html");
                response.setContentFile(file);
            }
        }
        response.addHeader("Server","WebServer");
    }
}
